// tr_image.h
//

enum idImageInternalFormat_t {
	IMG_RGBA8 = 0,
	IMG_RGB,
	IMG_RGB8,
	IMG_RGBA,
	IMG_RGBA_RT,
	IMG_COMPRESSED_RGBA_S3TC_DXT5_EXT,
	IMG_DEPTH_STENCIL
};

class idBinaryImage {
public:
	static void WriteBinaryImage( const char *name, byte *buffer, int width, int height );
	static bool ShouldGenerateBinaryImage( const char *name );
	static bool ReadBinaryImage( const char *name, byte **buffer, int *width, int *height );
};

typedef enum {
	BUFFER_IMAGE,
	BUFFER_SCALED,
	BUFFER_RESAMPLED,
	BUFFER_MAX_TYPES
} bufferMemType_t;

void *R_GetImageBuffer( int size, bufferMemType_t bufferType );

class idImage {
public:
	idImage();
	~idImage();

	void					Init( int width, int height, idImageInternalFormat_t format = IMG_RGBA );
	void					UploadBuffer( byte *buffer );
	void					UploadBuffer( byte *buffer, float width, float height );
	void					SetUploadCrop( float x, float y ) { _xcrop = x; _ycrop = y; };
	void					Resize( int width, int height );

	int						GetWidth() { return width; }
	int						GetHeight() { return height; }

	ID3D11Texture2D			*GetTextureHandle( void ) { return textureHandle; }

	void					Bind( int texNum );
private:
	void					Release( void );

	float					_xcrop;
	float					_ycrop;
	ID3D11Texture2D			*textureHandle;
	ID3D11ShaderResourceView *textureHandleRV;
	ID3D11SamplerState*      g_pSamplerLinear;
public:

	char imgName[MAX_QPATH];            // game path, including extension
	int width, height;                      // source image
	int uploadWidth, uploadHeight;          // after power of two and picmip but not including clamp to MAX_TEXTURE_SIZE
	void *texnum;                      // gl texture binding

	int frameUsed;                  // for texture usage in frame statistics

	idImageInternalFormat_t internalFormat;
	int TMU;                        // only needed for voodoo2

	qboolean mipmap;
	qboolean allowPicmip;
	qboolean characterMIP;      // independant 'character' mip scale ----(SA)	added

	int wrapClampMode;              // GL_CLAMP or GL_REPEAT

	int hash;           // for fast building of the backupHash

	idImage* next;

public:
	static const int				Clamp = 1 << 1;
	static const int				Wrap = 2 << 1;
	static const int				Repeat = 3 << 1;

	static const int				LINEAR_MIPMAP_NEAREST = 1 << 2;
	static const int				LINEAR = 2 << 2;
	static const int				NEAREST = 3 << 2;
	static const int				NEAREST_MIPMAP_NEAREST = 4 << 2;
	static const int				NEAREST_MIPMAP_LINEAR = 5 << 2;
	static const int				LINEAR_MIPMAP_LINEAR = 6 << 2;
};

typedef idImage image_t;

typedef struct {
	char *name;
	int minimize, maximize;
} textureMode_t;

extern textureMode_t modes[];
